$(function() {
	pageSource.init();
});

var pageSource = {
	init : function() {

		$.hcPostAjax({
			url : basePath + "/user/detail",
			data : {
				id : userId
			},
			async : false,
			success : function(data) {
				if (data.gender == 1) {
					data.gender = "男";
				} else if (data.gender == 2) {
					data.gender = "女";
				} else {
					data.gender = "未知";
				}
				renderFormData($("#m_widget5_tab1_content form"), data);
			}
		});
        
		$("#resetWord").on('click',function(){
			layer.confirm("是否重置密码？", {btn:["确认", "取消"]}, function(index) {
				$.hcPostAjax({
					showLoad : true,
					url : '../user/resrtWord',
					success : function(data) {
						layer.msg('重置默认密码123456成功,请重新登入', {
							icon : 1,time:1500
						}, function() {
							window.parent.logout();
						});

					},
					error : function() {
						layer.msg('更新失败');
					}
				});
			})
			
		});
		
		$("#updateWord").on(
				'click',
				function() {

					var oldWord = $("#oldWord").val();
					var newWord = $("#newWord").val();
					var confirmWord = $("#confirmWord").val();

					if (newWord != confirmWord) {
						layer.msg("新密码与确认密码不一致");
						return;
					}
					if (!(/^[\S]{6,12}$/.test(oldWord)
							&& /^[\S]{6,12}$/.test(newWord) && /^[\S]{6,12}$/
							.test(confirmWord))) {
						layer.msg("密码必须6到12位，且不能出现空格");
						return;
					}
					var param = {};
					param.oldWord = oldWord;
					param.newWord = newWord;
					param.confirmWord = confirmWord;
					$.hcPostAjax({
						showLoad : true,
						url : '../user/updateWord',
						data : param,
						success : function(data) {
							layer.msg('更新成功,请重新登入', {
								icon : 1,time:1500
							}, function() {
								window.parent.logout();
							});

						},
						error : function() {
							layer.msg('更新失败');
						}
					});

				})

	}
}